$("#file-1").fileinput({
    language: 'zh',
    theme: 'fas',
    uploadUrl: '/pluginConfig/upload', // you must set a valid URL here else you will get an error
    overwriteInitial: false,
    textEncoding:'UTF-8',
    //allowedFileExtensions: ['jpg', 'gif', 'png'],//接收的文件后缀
    //allowedFileTypes: ['image', 'video', 'flash'],
    //minImageWidth: 50, //图片的最小宽度
    //minImageHeight: 50,//图片的最小高度
    //maxImageWidth: 1000,//图片的最大宽度
    //maxImageHeight: 1000,//图片的最大高度
    //maxFileSize:0,//单位为kb，如果为0表示不限制文件大小
    //minFileCount: 0,
    maxFileCount:10, //表示允许同时上传的最大文件个数
    slugCallback: function (filename) {//不规则命名处理.
        return filename.replace('(', '_').replace(']', '_');
    }
});
//上传成功触发
$("#file-1").on("fileuploaded", function (event, data, previewId, index) {
    //上传图片名称
    var upload_img_name = previewId.substring(previewId.indexOf("_", index+1));
    var url=$("#del_name").val();
    if (url != null || url !=''){
        $("#del_name").val(url+data.response.message+upload_img_name+';');
    }
    console.log('upload_img_name:'+upload_img_name)
});
//上传成功后，缩略删除图片，触发事件 data包含图片本来得 name
$('#file-1').on('filesuccessremove', function(event, key, data) {
    console.log('event:'+event);
    console.log('key:'+key);
    console.log('data:'+data);
    var index=data.indexOf("_");
    //删除图片名称
    var del_img_name = key.substring(key.indexOf("_", index));
    console.log('del_img_name:'+del_img_name);
    //当前上传的图片，拼接后字符串
    var url=$("#del_name").val();
    console.log("原始url:"+url);
    var img_names = url.split(";");
    var del_name;
    for (var i = 0; i < img_names.length; i++) {
        if(img_names[i].indexOf(del_img_name) >= 0){
            del_name=img_names[i];
        }
    }
    console.log("当前删除url:"+del_name);
    url=url.replace(del_name+";","");
    console.log("删除后url:"+url);
    $.get("/pluginConfig/del",{"urls":del_name},function (data) {
        if(data.code == 200){
            $("#del_name").val(url);
        }else {
            console.log("code:"+data.code+",message:"+data.message);
        }
    })
});
//移除按钮触发事件
$('#file-1').on('filecleared', function() {
    var testVal = $("#del_name").val();
    var url=$("#del_name").val();
    console.log(url);
    if (testVal){
        $.get("/pluginConfig/del",{"urls":url},function (data) {
            if(data.code == 200){
                $("#del_name").val('');
                console.log("code:"+data.code+",message:"+data.message);
            }else {
                console.log("code:"+data.code+",message:"+data.message);
            }
        })
    }
});
